var swapNodes = function(head, k) {
  let before=head,after=head,begin=head;
  let a;
  let i=0;
  while(i!=k-1)
  {
      i++;
      before=before.next;
      begin=begin.next;
  }
  while(before.next)
  {
      before=before.next;
      after=after.next;
  }
  a=after.val;
  after.val=begin.val;
  begin.val=a;
  return head;
};